home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2001 June
/
CHIP Haziran 2001.iso
/
prog
/
haziran
/
19
/
setup.exe
/
data.z
/
iop480_diag.c
< prev
next >
Wrap
C/C++ Source or Header
|
2001-04-11
|
17KB
|
472 lines
////////////////////////////////////////////////////////////////
// File - IOP480_DIAG.C
//
// o A simple diagnostics program that lets you access the
// PLX IOP 480 registers and local memory.
// o This program is meant to be used as an example for using the IOP480_LIB.H API,
// you may use it as a skeleton for your driver, or 'cut & paste' parts
// of it into your device driver code.
// o For a more advanced monitor program, use the standard PLXMON.EXE
// from PLX.
//
////////////////////////////////////////////////////////////////
#include "../lib/iop480_lib.h"
#include "../../../samples/shared/pci_diag_lib.h"
#include <stdio.h>
// input of command from user
static char line[256];
void PLX_EditReg(IOP480_HANDLE hPlx)
{
struct
{
CHAR *name;
DWORD dwOffset;
DWORD dwVal;
} fields[30];
int cmd;
int i;
int field_count;
i = 0;
fields[i].name = "DEVINIT"; fields[i++].dwOffset = 0x80;
fields[i].name = "LAS0RR"; fields[i++].dwOffset = 0xa0;
fields[i].name = "LAS0BA"; fields[i++].dwOffset = 0xa4;
fields[i].name = "LAS1RR"; fields[i++].dwOffset = 0xa8;
fields[i].name = "LAS1BA"; fields[i++].dwOffset = 0xac;
fields[i].name = "EROMRR"; fields[i++].dwOffset = 0xc0;
fields[i].name = "EROMBA"; fields[i++].dwOffset = 0xc4;
fields[i].name = "MBOX0"; fields[i++].dwOffset = 0x180;
fields[i].name = "MBOX1"; fields[i++].dwOffset = 0x184;
fields[i].name = "MBOX2"; fields[i++].dwOffset = 0x188;
fields[i].name = "MBOX3"; fields[i++].dwOffset = 0x18c;
fields[i].name = "MBOX4"; fields[i++].dwOffset = 0x190;
fields[i].name = "MBOX5"; fields[i++].dwOffset = 0x194;
fields[i].name = "MBOX6"; fields[i++].dwOffset = 0x198;
fields[i].name = "MBOX7"; fields[i++].dwOffset = 0x19c;
fields[i].name = "P2LDBELL"; fields[i++].dwOffset = 0x1a0;
fields[i].name = "L2PDBELL"; fields[i++].dwOffset = 0x1a4;
fields[i].name = "PINTSTAT"; fields[i++].dwOffset = 0x1b0;
fields[i].name = "PINTENB"; fields[i++].dwOffset = 0x1b4;
fields[i].name = "LINTSTAT"; fields[i++].dwOffset = 0x1b8;
fields[i].name = "LINTENB"; fields[i++].dwOffset = 0x1bc;
field_count = i;
do
{
int row;
int col;
int row_count = field_count/2 + field_count%2;
printf ("\n");
printf ("Edit PLX IOP 480 registers\n");
printf ("--------------------------------\n");
for (row = 0; row<row_count; row++)
{
for (col = 0; col<=1; col++)
{
if (col==0) i = row;
else i = row + row_count;
if (i<field_count)
{
char buf[10];
fields[i].dwVal = IOP480_ReadReg(hPlx, fields[i].dwOffset);
sprintf(buf, "%08x",fields[i].dwVal);
printf ("%2d. %8s : %s ",i+1, fields[i].name, buf);
}
if (col==1) printf ("\n");
}
}
printf ("99. Back to main menu\n");
printf ("Choose register to write to, or 99 to exit: ");
cmd = 0;
fgets(line, sizeof(line), stdin);
sscanf (line, "%d",&cmd);
if (cmd>=1 && cmd <=21)
{
i = cmd-1;
printf ("Enter value to write to %s register (or 'X' to cancel): ",fields[i].name);
fgets(line, sizeof(line), stdin);
if (toupper (line[0])!='X')
{
DWORD dwVal;
dwVal = 0;
sscanf (line,"%x",&dwVal);
IOP480_WriteReg(hPlx, fields[i].dwOffset, dwVal);
}
}
} while (cmd!=99);
}
char *PLX_GetAddrRangeName(IOP480_ADDR addrSpace)
{
return
addrSpace==IOP480_ADDR_SPACE0 ? "Addr Space 0 - (BAR1)" :
addrSpace==IOP480_ADDR_SPACE1 ? "Addr Space 1 - (BAR2)" :
addrSpace==IOP480_ADDR_SPACE2 ? "Addr Space 2 - (BAR3)" :
addrSpace==IOP480_ADDR_SPACE3 ? "Addr Space 3 - (BAR4)" :
addrSpace==IOP480_ADDR_SPACE4 ? "Addr Space 4 - (BAR5)" :
addrSpace==IOP480_ADDR_EPROM ? "EEPROM Addr Space" : "Invalid";
}
void PLX_BoardAccess(IOP480_HANDLE hPlx, BOOL fLocalAddr)
{
int cmd, cmd2;
DWORD addr, data, i;
IOP480_ADDR ad_sp = IOP480_ADDR_SPACE0;
IOP480_MODE ad_mode = IOP480_MODE_DWORD;
char *pcMemoryType = fLocalAddr ? "local address" : "offset";
if (!fLocalAddr)
{
for (; ad_sp<=IOP480_ADDR_EPROM && !IOP480_IsAddrSpaceActive(hPlx, ad_sp); ad_sp++)
if (ad_sp>IOP480_ADDR_EPROM)
{
printf ("No active memory spaces on board!\n");
return;
}
}
do
{
printf ("Access the board's %s ranges\n",pcMemoryType);
printf ("-------------------------------------------\n");
printf ("(Access to invalid %s may hang the computer!)\n", pcMemoryType);
if (!fLocalAddr)
printf ("1. Change active memory space: %s\n",PLX_GetAddrRangeName(ad_sp));
printf ("2. Toggle active mode: %s\n",
ad_mode==IOP480_MODE_BYTE ? "BYTE (8 bit)" :
ad_mode==IOP480_MODE_WORD ? "WORD (16 bit)" : "DWORD (32 bit)");
printf ("3. Read from board\n");
printf ("4. Write to board\n");
printf ("99. Back to main menu\n");
printf ("\n");
printf ("Enter option: ");
cmd = 0;
fgets(line, sizeof(line), stdin);
sscanf (line, "%d",&cmd);
switch (cmd)
{
case 1:
if (!fLocalAddr)
{
printf ("Choose memory space:\n");
printf ("--------------------\n");
for (i=IOP480_ADDR_SPACE0; i<=IOP480_ADDR_EPROM; i++)
{
printf ("%d. %s", i, PLX_GetAddrRangeName(i));
if (IOP480_IsAddrSpaceActive(hPlx, i)) printf ("\n");
else printf (" - space not active\n");
}
printf ("Enter option: ");
cmd2 = 99;
fgets(line, sizeof(line), stdin);
sscanf (line, "%d",&cmd2);
if (cmd2>=IOP480_ADDR_SPACE0 && cmd2<=IOP480_ADDR_EPROM)
{
int new_ad_sp = cmd2;
if (IOP480_IsAddrSpaceActive(hPlx, new_ad_sp)) ad_sp = new_ad_sp;
else printf ("Chosen space not active!\n");
}
}
break;
case 2:
ad_mode = (ad_mode + 1) % 3;
break;
case 3:
printf ("Enter %s to read from: ", pcMemoryType);
fgets(line, sizeof(line), stdin);
sscanf (line, "%x", &addr);
switch (ad_mode)
{
case IOP480_MODE_BYTE:
if (fLocalAddr) data = IOP480_ReadByteLocal(hPlx, addr);
else data = IOP480_ReadByte(hPlx, ad_sp, addr);
break;
case IOP480_MODE_WORD:
if (fLocalAddr) data = IOP480_ReadWordLocal(hPlx, addr);
else data = IOP480_ReadWord(hPlx, ad_sp, addr);
break;
case IOP480_MODE_DWORD:
if (fLocalAddr) data = IOP480_ReadDWordLocal(hPlx, addr);
else data = IOP480_ReadDWord(hPlx, ad_sp, addr);
break;
}
printf ("Value read: %x\n", data);
break;
case 4:
printf ("Enter %s to write to: ", pcMemoryType);
fgets(line, sizeof(line), stdin);
sscanf (line, "%x", &addr);
printf ("Enter data to write %s: ",
ad_mode==IOP480_MODE_BYTE ? "BYTE (8 bit)" :
ad_mode==IOP480_MODE_WORD ? "WORD (16 bit)" : "DWORD (32 bit)");
fgets(line, sizeof(line), stdin);
sscanf (line, "%x",&data);
switch (ad_mode)
{
case IOP480_MODE_BYTE:
if (fLocalAddr) IOP480_WriteByteLocal(hPlx, addr, (BYTE) data);
else IOP480_WriteByte(hPlx, ad_sp, addr, (BYTE) data);
break;
case IOP480_MODE_WORD:
if (fLocalAddr) IOP480_WriteWordLocal(hPlx, addr, (WORD) data);
else IOP480_WriteWord(hPlx, ad_sp, addr, (WORD) data);
break;
case IOP480_MODE_DWORD:
if (fLocalAddr) IOP480_WriteDWordLocal(hPlx, addr, data);
else IOP480_WriteDWord(hPlx, ad_sp, addr, data);
break;
}
break;
}
} while (cmd!=99);
}
void WINAPI PLX_IntHandlerRoutine(IOP480_HANDLE hPlx, IOP480_INT_RESULT *intResult)
{
printf ("Got interrupt number %d\n", intResult->dwCounter);
}
void PLX_EnableDisableInterrupts(IOP480_HANDLE hPlx)
{
int cmd;
printf ("WARNING!!!\n");
printf ("----------\n");
printf ("Your hardware has level sensitive interrupts.\n");
printf ("You must modify the source code of IOP480_IntEnable(), in the file IOP480_lib.c,\n");
printf ("to acknowledge the interrupt before enabling interrupts.\n");
printf ("Without this modification, your PC will HANG upon interrupt!\n");
do
{
printf ("Enable / Disable interrupts\n");
printf ("---------------------------\n");
printf ("1. %s interrupts\n", IOP480_IntIsEnabled(hPlx) ? "Disable" : "Enable");
printf ("99. Back to main menu\n");
printf ("\n");
printf ("Enter option: ");
cmd = 0;
fgets(line, sizeof(line), stdin);
sscanf (line, "%d",&cmd);
switch (cmd)
{
case 1:
if (IOP480_IntIsEnabled(hPlx))
{
printf ("Disabling interrupt Int\n");
IOP480_IntDisable(hPlx);
}
else
{
printf ("Enabling interrupts\n");
if (!IOP480_IntEnable(hPlx, PLX_IntHandlerRoutine))
printf ("failed enabling interrupts\n");
}
break;
}
} while (cmd!=99);
}
void PLX_EEPROMAccess(IOP480_HANDLE hPlx)
{
int cmd;
DWORD addr;
DWORD dwData;
do
{
printf ("Access the board's serial EERPOM\n");
printf ("--------------------------------\n");
if (!IOP480_EEPROMValid(hPlx))
printf ("Note: PLX EEPROM valid BIT is 0\n");
printf (" Note: reading/writing to odd addresses is meaningless,\n");
printf (" as data is stored in words.\n");
printf ("1. Display EEPROM content\n");
printf ("2. Read dword from serial EEPROM on the board\n");
printf ("3. Write dword to the serial EEPROM on the board\n");
printf ("99. Back to main menu\n");
printf ("\n");
printf ("Enter option: ");
cmd = 0;
fgets(line, sizeof(line), stdin);
sscanf (line, "%d",&cmd);
switch (cmd)
{
case 1:
for (addr=0; addr<0xff; addr += 4)
{
if (!(addr % 0x10))
printf("\n %02x: ", addr);
if (!IOP480_EEPROMReadDWord(hPlx, addr, &dwData))
{
printf("\nError occured reading serial EEPROM - %s\n", IOP480_ErrorString);
break;
}
printf("%08x ", dwData);
}
printf ("\n");
break;
case 2:
printf ("Enter addr to read from (0-ff): ");
fgets(line, sizeof(line), stdin);
sscanf (line, "%x", &addr);
if (IOP480_EEPROMReadDWord(hPlx, addr, &dwData))
printf ("Value read: %x\n", dwData);
else
printf("Error occured reading serial EEPROM - %s\n", IOP480_ErrorString);
break;
case 3:
printf ("Enter addr to write to (0-ff): ");
fgets(line, sizeof(line), stdin);
sscanf (line, "%x", &addr);
printf ("Enter data to write: ");
fgets(line, sizeof(line), stdin);
sscanf (line, "%x",&dwData);
if (!IOP480_EEPROMWriteDWord(hPlx, addr, dwData))
printf("Error occured reading serial EEPROM - %s\n", IOP480_ErrorString);
break;
default:
break;
}
} while (cmd!=99);
}
IOP480_HANDLE PLX_LocateAndOpenBoard(DWORD dwVendorID, DWORD dwDeviceID, BOOL fUseInt)
{
DWORD cards, my_card;
IOP480_HANDLE hPlx = NULL;
if (dwVendorID==0)
{
printf ("Enter VendorID: ");
fgets(line, sizeof(line), stdin);
sscanf (line, "%x",&dwVendorID);
if (dwVendorID==0) return NULL;
printf ("Enter DeviceID: ");
fgets(line, sizeof(line), stdin);
sscanf (line, "%x",&dwDeviceID);
}
cards = IOP480_CountCards (dwVendorID, dwDeviceID);
if (cards==0)
{
printf("%s", IOP480_ErrorString);
return NULL;
}
else if (cards==1) my_card = 1;
else
{
DWORD i;
printf("Found %d matching PCI cards\n", cards);
printf("Select card (1-%d): ", cards);
i = 0;
fgets(line, sizeof(line), stdin);
sscanf (line, "%d",&i);
if (i>=1 && i <=cards) my_card = i;
else
{
printf ("Choice out of range\n");
return NULL;
}
}
if (IOP480_Open (&hPlx, dwVendorID, dwDeviceID, my_card - 1, fUseInt ? IOP480_OPEN_USE_INT : 0))
printf ("PLX IOP 480 PCI card found!\n");
else printf ("%s", IOP480_ErrorString);
return hPlx;
}
int main(int argc, char *argv[])
{
int cmd;
IOP480_HANDLE hPlx = NULL;
HANDLE hWD;
BOOL fUseInt = FALSE; // by default - do not install interrupts
BOOL fOpenedWithInt = fUseInt;
printf ("PLX IOP 480 diagnostic utility.\n");
printf ("Application accesses hardware using " WD_PROD_NAME ".\n");
// make sure WinDriver is loaded
if (!PCI_Get_WD_handle(&hWD)) return 0;
WD_Close (hWD);
hPlx = PLX_LocateAndOpenBoard(0x10b5, 0x0480, fUseInt);
do
{
printf ("\n");
printf ("PLX IOP 480 main menu\n");
printf ("-------------------\n");
printf ("1. Scan PCI bus\n");
printf ("2. Set opening board %s interrupts\n", fUseInt ? "without" : "with");
printf ("3. Locate/Choose PLX IOP 480 board (%s interrupts)\n", fUseInt ? "with" : "without");
if (hPlx)
{
printf ("4. PCI configuration registers\n");
printf ("5. PLX IOP 480 local registers\n");
printf ("6. Access address spaces on the board\n");
printf ("7. Access local address ranges on the board\n");
if (fOpenedWithInt)
printf ("8. Enable / Disable interrupts\n");
printf ("9. Access serial EEPROM on the board\n");
}
printf ("99. Exit\n");
printf ("Enter option: ");
cmd = 0;
fgets(line, sizeof(line), stdin);
sscanf (line, "%d",&cmd);
switch (cmd)
{
case 1: // Scan PCI bus
PCI_Print_all_cards_info();
break;
case 2: // Set open board with / without interrupts
fUseInt = !fUseInt;
break;
case 3: // Locate PLX IOP 480 board
if (hPlx) IOP480_Close(hPlx);
hPlx = PLX_LocateAndOpenBoard(0, 0, fUseInt);
if (!hPlx) printf ("PLX card open failed!\n");
fOpenedWithInt = fUseInt;
break;
case 4: // PCI configuration registers
if (hPlx)
{
WD_PCI_SLOT pciSlot;
IOP480_GetPciSlot(hPlx, &pciSlot);
PCI_EditConfigReg(pciSlot);
}
break;
case 5: // PLX IOP 480 local registers
if (hPlx) PLX_EditReg(hPlx);
break;
case 6: // Access address spaces on the board
if (hPlx) PLX_BoardAccess(hPlx, FALSE);
break;
case 7: // Access local address ranges on the board
if (hPlx) PLX_BoardAccess(hPlx, TRUE);
break;
case 8: // Enable / Disable interrupts
if (hPlx && fOpenedWithInt) PLX_EnableDisableInterrupts(hPlx);
break;
case 9: // Access serial EEPROM on the board
if (hPlx) PLX_EEPROMAccess(hPlx);
break;
}
} while (cmd!=99);
if (hPlx) IOP480_Close(hPlx);
return 0;
}